<template>
  <div class="panel-tab__content">
    <el-form size="mini" label-width="90px" @submit.native.prevent>
      <el-form-item label="ID" style="display: none;">
        <el-input
		  :disabled="idEditDisabled || elementBaseInfo.$type === 'bpmn:Process'"
          v-model="elementBaseInfo.id"
          clearable
          @change="updateBaseInfo('id')"
        />
      </el-form-item>
      <el-form-item label="意见" v-if="showSelect == 1">
		<el-select v-model="elementBaseInfo.name" @change="updateBaseInfo('name')">
		  <el-option label="同意" value="同意" />
		  <el-option label="拒绝" value="拒绝" />
		</el-select>
      </el-form-item>
      <el-form-item label="名称" v-else>
		<el-input v-model="elementBaseInfo.name" clearable @change="updateBaseInfo('name')" />
      </el-form-item>
      <!--流程的基础属性-->
      <template v-if="elementBaseInfo.$type === 'bpmn:Process'">
        <el-form-item label="版本标签" style="display: none;">
          <el-input v-model="elementBaseInfo.versionTag" clearable @change="updateBaseInfo('versionTag')" />
        </el-form-item>
        <el-form-item label="可执行" style="display: none;">
          <el-switch v-model="elementBaseInfo.isExecutable" active-text="是" inactive-text="否" @change="updateBaseInfo('isExecutable')" />
        </el-form-item>
      </template>
    </el-form>
  </div>
</template>
<script>
	import Utils from '../../utils.js';

export default {
  name: "ElementBaseInfo",
  props: {
    businessObject: Object,
    type: String,
    idEditDisabled: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      elementBaseInfo: {},
	  showSelect:0
    };
  },
  watch: {
    businessObject: {
      immediate: false,
      handler: function(val) {
        if (val) {
          this.$nextTick(() => this.resetBaseInfo());
        }
      }
    }
  },
  methods: {
    resetBaseInfo() {
      this.bpmnElement = window?.bpmnInstances?.bpmnElement;
	  if(this.bpmnElement.source == undefined){
	  		  this.showSelect = 0;
	  }else if(this.bpmnElement.source.type == 'bpmn:ExclusiveGateway'){
		  this.showSelect = 1;
	  }else{
		  this.showSelect = 0;
	  }
      this.elementBaseInfo = JSON.parse(JSON.stringify(this.bpmnElement.businessObject));
    },
    updateBaseInfo(key) {
      const attrObj = Object.create(null);
      attrObj[key] = this.elementBaseInfo[key];
      if (key === "id") {
        window.bpmnInstances.modeling.updateProperties(this.bpmnElement, {
          id: this.elementBaseInfo[key],
          di: { id: this.elementBaseInfo[key] }
        });
      } else {
        window.bpmnInstances.modeling.updateProperties(this.bpmnElement, attrObj);
      }
	  Utils.$emit('demo','msg');
    }
  },
  beforeDestroy() {
    this.bpmnElement = null;
  }
};
</script>
